package com.point.community;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.demo.bean.PageBean;
import com.alibaba.dubbo.demo.SysFunctionInterface;
import com.alibaba.dubbo.demo.SysDeptInfoInterface;
import com.alibaba.dubbo.demo.SysRoleFuncInterface;
import com.alibaba.dubbo.demo.SysRoleInterface;
import com.alibaba.dubbo.demo.SysUserInfoInterface;
import com.alibaba.dubbo.demo.SysUserRoleInterface;
import com.alibaba.dubbo.demo.bean.SysDeptInfo;
import com.alibaba.dubbo.demo.bean.SysFunction;
import com.alibaba.dubbo.demo.bean.SysRole;
import com.alibaba.dubbo.demo.bean.SysRoleFunc;
import com.alibaba.dubbo.demo.bean.SysUserRole;
import com.alibaba.dubbo.demo.bean.SysUserinfo;
import com.point.community.bean.dwzPageData;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class SysUserInfoAction extends JsonAction {
	Logger logger = Logger.getLogger(SysUserInfoAction.class);
	
	private String msg = "";
	private boolean success = false;
	private String key = "";
	private String obj = "";
	private PageBean pageBean;
	
	private String statusCode,message,navTabId,rel,callbackType,forwardUrl,confirmMsg;
	public String getStatusCode() {
		return statusCode;
	}
	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getNavTabId() {
		return navTabId;
	}
	public void setNavTabId(String navTabId) {
		this.navTabId = navTabId;
	}
	public String getRel() {
		return rel;
	}
	public void setRel(String rel) {
		this.rel = rel;
	}
	public String getCallbackType() {
		return callbackType;
	}
	public void setCallbackType(String callbackType) {
		this.callbackType = callbackType;
	}
	public String getForwardUrl() {
		return forwardUrl;
	}
	public void setForwardUrl(String forwardUrl) {
		this.forwardUrl = forwardUrl;
	}
	public String getConfirmMsg() {
		return confirmMsg;
	}
	public void setConfirmMsg(String confirmMsg) {
		this.confirmMsg = confirmMsg;
	}

	private List<SysUserinfo> sysUserinfoList = new ArrayList<SysUserinfo>();
	private List<SysUserinfo> sysUserRightList = new ArrayList<SysUserinfo>();

	private SysUserinfo sysUserinfo = new SysUserinfo();
	
	
	@Autowired
	private SysUserInfoInterface sysUserInfoService;
	@Autowired
	private SysDeptInfoInterface sysDeptInfoService;
	
	@Autowired
	private SysRoleFuncInterface sysRoleFuncService;
	@Autowired
	private SysUserRoleInterface sysUserRoleService;
	
	@Autowired
	private SysFunctionInterface sysFuncService;
	@Autowired
	private SysRoleInterface sysRoleService;
	
	private List<SysFunction> sysFunctionList = new ArrayList<SysFunction>();
	
	public SysDeptInfoInterface getSysDeptInfoService() {
		return sysDeptInfoService;
	}

	public void setSysDeptInfoService(SysDeptInfoInterface sysDeptInfoService) {
		this.sysDeptInfoService = sysDeptInfoService;
	}	

	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public String getObj() {
		return obj;
	}
	public void setObj(String obj) {
		this.obj = obj;
	}

	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}

	public List<SysUserinfo> getSysUserinfoList() {
		return sysUserinfoList;
	}
	public void setSysUserinfoList(List<SysUserinfo> sysUserinfoList) {
		this.sysUserinfoList = sysUserinfoList;
	}
	public List<SysUserinfo> getSysUserRightList() {
		return sysUserRightList;
	}
	public void setSysUserRightList(List<SysUserinfo> sysUserRightList) {
		this.sysUserRightList = sysUserRightList;
	}
	public SysUserinfo getSysUserinfo() {
		return sysUserinfo;
	}
	public void setSysUserinfo(SysUserinfo sysUserinfo) {
		this.sysUserinfo = sysUserinfo;
	}
	
	public SysUserInfoInterface getSysUserInfoService() {
		return sysUserInfoService;
	}
	public void setSysUserInfoService(SysUserInfoInterface sysUserInfoService) {
		this.sysUserInfoService = sysUserInfoService;
	}
	public SysRoleInterface getSysRoleService() {
		return sysRoleService;
	}

	public void setSysRoleService(SysRoleInterface sysRoleService) {
		this.sysRoleService = sysRoleService;
	}
	/**
	 * 获取所有用户信息
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String webQueryAllSysUserInfo() {
		logger.error("enter com.point.community.SysUserInfoAction.webQueryAllSysUserInfo");
		
		String currentPage = request.getParameter("pageNum");
		String numPerPage = request.getParameter("numPerPage");
		if(StringUtils.isEmpty(currentPage)){
			currentPage = "1";
	    }
	    if(StringUtils.isEmpty(numPerPage)){
	    	numPerPage = "20";
	    }
	    int nCurrentPage =  Integer.parseInt(currentPage);    
	    int nNumPerPage =  Integer.parseInt(numPerPage);  
	    int nStart = (nCurrentPage - 1)*nNumPerPage;
		String start = Integer.toString(nStart);

		pageBean = new PageBean(start, numPerPage);
		
		int ndeptid=0;
		if(getParameterInteger("deptid")!=null)
			ndeptid=getParameterInteger("deptid");
		String usercode = "";
		if(getParameterString("usercode")!=null)
			usercode = getParameterString("usercode");
		String username = "";
		if(getParameterString("username")!=null)
			username = getParameterString("username");
		logger.error("webQueryAllSysUserInfo username="+username+" usercode="+usercode);
		pageBean = sysUserInfoService.queryAllUserInfo(pageBean,ndeptid,usercode,username);
		sysUserinfoList = pageBean.getResultList();
		request.getSession().setAttribute("sysUserinfoList", sysUserinfoList);
		request.getSession().setAttribute("totalCount", pageBean.getTotal());
		request.getSession().setAttribute("numPerPage", numPerPage);
		request.getSession().setAttribute("pageNumShown", "5");
		request.getSession().setAttribute("currentPage", currentPage);
		request.getSession().setAttribute("username", username);
		request.getSession().setAttribute("usercode", usercode);
		
		return "userinfo";
	}
	
	@SuppressWarnings("unchecked")
	public String webQueryAllSysUserDeptInfo() {
		logger.error("enter com.point.community.SysUserInfoAction.webQueryAllSysUserDeptInfo");
		
		String currentPage = request.getParameter("pageNum");
		String numPerPage = request.getParameter("numPerPage");
		if(StringUtils.isEmpty(currentPage)){
			currentPage = "1";
	    }
	    if(StringUtils.isEmpty(numPerPage)){
	    	numPerPage = "20";
	    }
	    int nCurrentPage =  Integer.parseInt(currentPage);    
	    int nNumPerPage =  Integer.parseInt(numPerPage);  
	    int nStart = (nCurrentPage - 1)*nNumPerPage;
		String start = Integer.toString(nStart);

		pageBean = new PageBean(start, numPerPage);
		
		int ndeptid=0;
		if(getParameterInteger("deptid")!=null)
			ndeptid=getParameterInteger("deptid");
		String usercode = "";
		if(getParameterString("usercode")!=null)
			usercode = getParameterString("usercode");
		String username = "";
		if(getParameterString("username")!=null)
			username = getParameterString("username");
		
		pageBean = sysUserInfoService.queryAllUserInfo(pageBean,ndeptid,usercode,username);
		sysUserinfoList = pageBean.getResultList();
		int count = pageBean.getTotal().intValue();
		request.getSession().setAttribute("sysUserinfoList", sysUserinfoList);
		request.getSession().setAttribute("totalCount", count);
		request.getSession().setAttribute("numPerPage", numPerPage);
		request.getSession().setAttribute("pageNumShown", "5");
		request.getSession().setAttribute("currentPage", currentPage);
		request.getSession().setAttribute("username", username);
		request.getSession().setAttribute("usercode", usercode);
		
		dwzPageData dwz = new dwzPageData();
		dwz.currentPage = currentPage;
		dwz.numPerPage = numPerPage;
		dwz.totalCount = (long) pageBean.getTotal();
		request.getSession().setAttribute("userInfoDwzData", dwz);
		
		return "userdeptinfo";
	}
	
	@SuppressWarnings("unchecked")
	public String webQuerySysUserRightInfo() {
		logger.error("enter com.point.community.SysUserInfoAction.webQuerySysUserRightInfo");
		
		String currentPage = request.getParameter("pageNum");
		String numPerPage = request.getParameter("numPerPage");
		if(StringUtils.isEmpty(currentPage)){
			currentPage = "1";
	    }
	    if(StringUtils.isEmpty(numPerPage)){
	    	numPerPage = "20";
	    }
	    int nCurrentPage =  Integer.parseInt(currentPage);    
	    int nNumPerPage =  Integer.parseInt(numPerPage);  
	    int nStart = (nCurrentPage - 1)*nNumPerPage;
		String start = Integer.toString(nStart);

		pageBean = new PageBean(start, numPerPage);
		
		String deptcode = "";
		if(getParameterString("deptcode")!=null)
			deptcode = getParameterString("deptcode");
		if(StringUtils.isEmpty(deptcode))
			deptcode = "0";
		
		String deptname = "";
		if(getParameterString("deptname")!=null)
			deptname = getParameterString("deptname");
		
		String usercode = "";
		if(getParameterString("usercode")!=null)
			usercode = getParameterString("usercode");
		String username = "";
		if(getParameterString("username")!=null)
			username = getParameterString("username");
		
		String deptlist = "";
		List<SysDeptInfo> objDeptList = sysDeptInfoService.queryDeptTree(false, Integer.valueOf(deptcode), deptname);
		if(objDeptList!=null)
		{
			for(SysDeptInfo item : objDeptList)
			{
				if(deptlist.equals(""))
					deptlist += Integer.toString(item.getDeptid());
				else
					deptlist += "," + Integer.toString(item.getDeptid());
			}
		}
		
		pageBean = sysUserInfoService.queryAllUserInfo(pageBean,usercode,username,deptlist);
		
		sysUserRightList = pageBean.getResultList();
		int count = pageBean.getTotal().intValue();
		request.getSession().setAttribute("sysUserRightList", sysUserRightList);
		request.getSession().setAttribute("totalCount", count);
		request.getSession().setAttribute("numPerPage", numPerPage);
		request.getSession().setAttribute("pageNumShown", "5");
		request.getSession().setAttribute("currentPage", currentPage);
		request.getSession().setAttribute("username", username);
		request.getSession().setAttribute("usercode", usercode);
		request.getSession().setAttribute("deptcode", deptcode);
		request.getSession().setAttribute("deptname", deptname);		
		dwzPageData dwz = new dwzPageData();
		dwz.currentPage = currentPage;
		dwz.numPerPage = numPerPage;
		dwz.totalCount = (long) pageBean.getTotal();
		request.getSession().setAttribute("userRightInfoDwzData", dwz);
		return "userrightinfo";
	}
	
	public SysRoleFuncInterface getSysRoleFuncService() {
		return sysRoleFuncService;
	}
	public void setSysRoleFuncService(SysRoleFuncInterface sysRoleFuncService) {
		this.sysRoleFuncService = sysRoleFuncService;
	}
	public SysUserRoleInterface getSysUserRoleService() {
		return sysUserRoleService;
	}
	public void setSysUserRoleService(SysUserRoleInterface sysUserRoleService) {
		this.sysUserRoleService = sysUserRoleService;
	}
	public SysFunctionInterface getSysFuncService() {
		return sysFuncService;
	}
	public void setSysFuncService(SysFunctionInterface sysFuncService) {
		this.sysFuncService = sysFuncService;
	}
	public List<SysFunction> getSysFunctionList() {
		return sysFunctionList;
	}
	public void setSysFunctionList(List<SysFunction> sysFunctionList) {
		this.sysFunctionList = sysFunctionList;
	}
	public String GetDeptName(List<SysDeptInfo> deptList,int deptid)
	{
		if(deptList==null)
			return "";
		for(SysDeptInfo item : deptList){
		   if(item.getDeptid()==deptid)
			   return item.getDeptname();
		}
		return "";
	}
	
	public String jsonQueryAllSysUserInfo()
	{
		int ndeptid=0;
		if(getParameterInteger("deptid")!=null)
			ndeptid=getParameterInteger("deptid");
		String usercode = "";
		if(getParameterString("usercode")!=null)
			usercode = getParameterString("usercode");
		String username = "";
		if(getParameterString("username")!=null)
			username = getParameterString("username");
		
		sysUserinfoList = sysUserInfoService.queryAllUserInfoList(ndeptid,usercode,username);
		
		if(sysUserinfoList.size()>0)
		{
			success = true;
			msg = "请求成功！";
		}
		else
		{
			success = false;
			msg = "请求失败或无数据！";						
		}
		return SUCCESS;
	}
	
	
	
	
	/**
	 * 按照用户帐号查询用户信息
	 */
	public String webQuerySysUserInfoByUserCode() 
	{
		logger.error(request.getRequestURL());
		String usercode = getParameterString("usercode");
		logger.error("webQuerySysUserInfoByUserCode usercode="+usercode);
		if(StringUtils.isEmpty(usercode))
			usercode ="admin";
		sysUserinfo = sysUserInfoService.getUserInfoByUserCode(usercode);
		//SysUserDeptinfo sysUserDeptInfo = new SysUserDeptinfo(sysUserinfo);
		//sysUserDeptInfo.setDeptName(deptName);
		if(sysUserinfo!=null){
			request.getSession().setAttribute("sysUserinfo", sysUserinfo);
			return "userinfoupdate";
		}
		else{
			return "error";
		}
	}
	
	public String jsonQuerySysUserInfoByUserCode() 
	{
		JSONObject jsonObj = getJsonObjFromRequest();
		String usercode = jsonObj.getString("usercode");
		sysUserinfo = sysUserInfoService.getUserInfoByUserCode(usercode);
		if(sysUserinfo!=null)
		{
			success = true;
			msg = "请求成功！";
		}
		else
		{
			success = false;
			msg = "请求失败或无数据！";						
		}	

		return SUCCESS;
	}	
	
	/**
	 * 按照用户姓名查询用户信息
	 */
	public String webQuerySysUserInfoByUserName() 
	{
		String username = getParameterString("username");
		sysUserinfo = sysUserInfoService.getUserInfoByUserCode(username);

		request.getSession().setAttribute("sysUserinfo", sysUserinfo);
		request.getSession().setAttribute("endPage", pageBean.getEndPage());
		request.getSession().setAttribute("pageNo", pageBean.getPage());
		request.getSession().setAttribute("total", pageBean.getTotal());

		return "SysUserInfo";
	}
	public String jsonQuerySysUserInfoByUserName() 
	{
		JSONObject jsonObj = getJsonObjFromRequest();
		String username = jsonObj.getString("username");
		sysUserinfo = sysUserInfoService.getUserInfoByUserCode(username);
		if(sysUserinfo!=null)
		{
			success = true;
			msg = "请求成功！";
		}
		else
		{
			success = false;
			msg = "请求失败或无数据！";						
		}	

		return SUCCESS;
	}	
	
	private boolean AppendFuncItem(List<SysRoleFunc> sysUserFuncList,SysRoleFunc item)
	{
		if(sysUserFuncList.size()<1)
		{
			sysUserFuncList.add(item);
			return true;
		}
		for(int i=0;i<sysUserFuncList.size();i++)
		{
			if(sysUserFuncList.get(i).getFuncid()==item.getFuncid())
			{
				if(item.getDataright()==1)
					sysUserFuncList.get(i).setDataright(1);
				return true;
			}
		}
		sysUserFuncList.add(item);
		return true;
	}
	private List<SysRoleFunc> getUserFuncList(int userid)
	{
		List<SysRoleFunc> sysUserFuncList = new ArrayList<SysRoleFunc>();
		List<SysUserRole> rolelist = sysUserRoleService.queryAllSysUserRoleList(userid, "", "", 0, "", "");
		for(SysUserRole role:rolelist)
		{
			List<SysRoleFunc> sysRoleFuncList = sysRoleFuncService.queryAllSysRoleFuncList(role.getRoleid());
			for(SysRoleFunc func:sysRoleFuncList)
				AppendFuncItem(sysUserFuncList,func);
		}
		
		return sysUserFuncList;
	}
	
	private List<Integer> getUserRightDept(int userid)
	{
		List<Integer> listDept = new ArrayList<Integer>();
		List<SysUserRole> rolelist = sysUserRoleService.queryAllSysUserRoleList(userid, "", "", 0, "", "");
		for(SysUserRole role:rolelist)
		{
			SysRole sysRole = sysRoleService.queryOneSysRole(role.getRoleid());
			if(sysRole==null)
				continue;
			String sRightDepts = sysRole.getDeptrightid();
			if(sRightDepts==null)
				continue;
			String[] DeptIdList= sRightDepts.split(","); 
			if(DeptIdList==null)
				continue;
			for(int i=0;i<DeptIdList.length;i++)
			{
				boolean isContain = false;
				for(int j=0;j<listDept.size();j++)
				{
					if(Integer.parseInt(DeptIdList[i])==listDept.get(j))
						isContain = true;
				}
				if(!isContain)
					listDept.add(Integer.parseInt(DeptIdList[i]));
			}
		}
		return listDept;
	}
	
	public SysRoleFunc GetRightFunc(int funcid,List<SysRoleFunc> rightlist)
	{
		if(rightlist==null)
			return null;
		for(int i=0;i<rightlist.size();i++)
		{
			if(funcid == Integer.parseInt(rightlist.get(i).getFuncid()))
				return rightlist.get(i);
		}
		return null;
	}
	
	public String jsonQuerySysRoleFunc()
	{
		int roleid = -1;
		if(request.getParameterValues("roleid")!=null)
			roleid = getParameterInteger("roleid");
		logger.error("jsonQuerySysRoleFunc roleid="+roleid);
		List<SysFunction> sysFuncTempList = sysFuncService.queryAllSysFuncList(-1);
		List<SysRoleFunc> sysRoleFuncList = sysRoleFuncService.queryAllSysRoleFuncList(roleid);

		for(int i=0;i<sysFuncTempList.size();i++)
		{
			SysFunction item = sysFuncTempList.get(i);
			if(item.getUpperid()!=0)
				continue;
			sysFunctionList.add(item);
			for(int j=0;j<sysFuncTempList.size();j++)
			{
				SysFunction itemChild = new SysFunction();
				itemChild = sysFuncTempList.get(j);
				
				if(itemChild.getUpperid()==item.getFuncid())
				{
					SysRoleFunc roleFunc = GetRightFunc(itemChild.getFuncid(),sysRoleFuncList);
					if(roleFunc==null)
					{	
						logger.error("roleFunc==null");
						itemChild.setLevel(0);
						itemChild.setRighttype(0);
					}
					else
					{
						logger.error(+roleFunc.getRoleid()+"\t"+roleFunc.getFuncid()+"\t"+roleFunc.getFuncname()+"\t"+roleFunc.getDataright()+"\t");
						itemChild.setLevel(1);
						itemChild.setRighttype(roleFunc.getDataright());
					}
					sysFunctionList.add(itemChild);
				}
			}
		}
		
		success = true;
		msg = "请求成功！";
		return SUCCESS;
	}
	
	public String jsonQuerySysUserFunc()
	{
		int userid = -1;
		if(request.getParameterValues("userid")!=null)
			userid = getParameterInteger("userid");
		logger.error("jsonQuerySysRoleFunc roleid="+userid);
		List<SysFunction> sysFuncTempList = sysFuncService.queryAllSysFuncList(-1);
		List<SysRoleFunc> sysRoleFuncList = getUserFuncList(userid);

		for(int i=0;i<sysFuncTempList.size();i++)
		{
			SysFunction item = sysFuncTempList.get(i);
			if(item.getUpperid()!=0)
				continue;
			sysFunctionList.add(item);
			for(int j=0;j<sysFuncTempList.size();j++)
			{
				SysFunction itemChild = new SysFunction();
				itemChild = sysFuncTempList.get(j);
				
				if(itemChild.getUpperid()==item.getFuncid())
				{
					SysRoleFunc roleFunc = GetRightFunc(itemChild.getFuncid(),sysRoleFuncList);
					if(roleFunc==null)
					{	
						logger.error("roleFunc==null");
						itemChild.setLevel(0);
						itemChild.setRighttype(0);
					}
					else
					{
						logger.error(+roleFunc.getRoleid()+"\t"+roleFunc.getFuncid()+"\t"+roleFunc.getFuncname()+"\t"+roleFunc.getDataright()+"\t");
						itemChild.setLevel(1);
						itemChild.setRighttype(roleFunc.getDataright());
					}
					sysFunctionList.add(itemChild);
				}
			}
		}
		
		success = true;
		msg = "请求成功！";
		return SUCCESS;
	}
	/**
	 * 登录
	 */
	public String login() {
		String usercode = getParameterString("usercode");
		String password = getParameterString("password");
		request.removeAttribute("msg");
		SysUserinfo user = new SysUserinfo();
		logger.error("usercode=" + usercode + " password=" + password);
		if (usercode != null && !usercode.equals("")) {
			user = sysUserInfoService.getUserInfoByUserCode(usercode);
			if (user != null) {
				if (user.getUserpwd().equals(password)) {
					//获取权限部门
					JSONObject json = new JSONObject();
					List<Integer> rightDeptIdList = getUserRightDept(user.getUserid());
					json.put("rightDeptIdList", rightDeptIdList);
					request.getSession().setAttribute("rightDeptIdListJson", json.toString());
					//获取权限功能
					List<SysRoleFunc> sysUserFuncList = getUserFuncList(user.getUserid());
					json.clear();
					json.put("sysUserFuncList", sysUserFuncList);
					request.getSession().setAttribute("sysUserFuncListJson", json.toString());
					//加载部门信息到session
					List<SysDeptInfo> deptList = sysDeptInfoService.queryDeptTree(true,0, "");
					json.clear();
					json.put("deptTreeSession", deptList);
					request.getSession().setAttribute("deptTreeJson", json.toString());
					request.getSession().setAttribute("userid", user.getUserid().toString());
					request.getSession().setAttribute("usercode", user.getUsercode());
					
					logger.error("userid:"+request.getSession().getAttribute("userid"));
					logger.error("usercode:"+request.getSession().getAttribute("usercode"));
					logger.error("rightDeptIdListJson:"+request.getSession().getAttribute("rightDeptIdListJson"));
					logger.error("sysUserFuncListJson:"+request.getSession().getAttribute("sysUserFuncListJson"));
					logger.error("deptTreeJson:"+request.getSession().getAttribute("deptTreeJson"));
					return "index";
				} else {
					request.setAttribute("msg", "密码错误！");
				}
			} else {
				request.setAttribute("msg", "用户不存在！");
			}
		} else {
			request.setAttribute("msg", "用户名为空！");
		}
		return "login";
	}
	
	/**
	 * 修改密码
	 */
	public String changePassword() {
		String usercode = getParameterString("usercode");
		String oldPassword = getParameterString("oldPassword");
		String newPassword1 = getParameterString("newPassword1");
		String newPassword2 = getParameterString("newPassword2");
		SysUserinfo user = new SysUserinfo();
		user = sysUserInfoService.getUserInfoByUserCode(usercode); 
		
		if(!newPassword1.equals(newPassword2))
		{
			msg = "两次输入新密码不一致！";
			success = false;
			request.getSession().setAttribute("errMsg", msg);
			return SUCCESS;			
		}
		if (user == null) {
			msg = "用户不存在！";
			success = false;
			request.getSession().setAttribute("errMsg", msg);
			return SUCCESS;
		}
		if (!user.getUserpwd().equals(oldPassword)) {
			msg = "密码错误！";
			success = false;
			request.getSession().setAttribute("errMsg", msg);
			return SUCCESS;
		}
		user.setUserpwd(newPassword1);
		boolean ret = sysUserInfoService.updateUserInfo(user);
		if (ret) {
			msg = "修改密码成功,请记住新密码！";
			success = true;
			return SUCCESS;
		}
		msg = "修改密码失败！请重试！";
		success = false;
		request.getSession().setAttribute("errMsg", msg);
		return SUCCESS;
	}
	
	/**
	 * 保存用户信息
	 */
	public String webSaveSysUserInfo() {
		sysUserinfo.setDeptid(this.getParameterInteger("deptid"));
		sysUserinfo.setUsername(getParameterString("username"));
		sysUserinfo.setUsercode(getParameterString("usercode"));
		sysUserinfo.setUserpwd(getParameterString("userpwd"));
		sysUserinfo.setPhone(getParameterString("phone"));
		sysUserinfo.setRemark(getParameterString("remark"));
	   boolean ret =  sysUserInfoService.saveUserInfo(sysUserinfo);
	   if (ret) 
	   {
			success = true;
			logger.info("保存用户信息成功!");
			
			statusCode="200";
			message="操作成功";
			navTabId="userinfo";
			rel="";
			callbackType="closeCurrent";
			forwardUrl="";
			confirmMsg="";
		}
	   else
	   {
		    success = true;
			logger.info("保存用户信息异常!");
			
			statusCode="200";
			message="操作失败";
			navTabId="userinfo";
			rel="";
			callbackType="closeCurrent";
			forwardUrl="";
			confirmMsg="";
			return SUCCESS;
	   }
		return SUCCESS;
	}
	
	/**
	 * 更新用户信息
	 */
	public String webUpdateUserInfo() { 
		sysUserinfo.setUserid(getParameterInteger("userid"));
		if(getParameterInteger("orgLookup.deptid")!=null)
			sysUserinfo.setDeptid(this.getParameterInteger("orgLookup.deptid"));
		else
			sysUserinfo.setDeptid(this.getParameterInteger("deptid"));
		sysUserinfo.setUsername(getParameterString("username"));
		sysUserinfo.setUsercode(getParameterString("usercode"));
		sysUserinfo.setUserpwd(getParameterString("userpwd"));
		sysUserinfo.setPhone(getParameterString("phone"));
		sysUserinfo.setRemark(getParameterString("remark"));
	   boolean ret =  sysUserInfoService.updateUserInfo(sysUserinfo);
	   if (ret) 
	   {
			success = true;
			logger.info("更新用户信息成功!");
			
			statusCode="200";
			message="操作成功";
			navTabId="userinfo";
			rel="";
			callbackType="closeCurrent";
			forwardUrl="";
			confirmMsg="";
		}
	   else
	   {
		    success = true;
			logger.info("更新用户信息异常!");
			
			statusCode="200";
			message="操作失败";
			navTabId="userinfo";
			rel="";
			callbackType="closeCurrent";
			forwardUrl="";
			confirmMsg="";
			return SUCCESS;
	   }
		return SUCCESS;
	}
	
	public String jsonUpdateUserInfo() 
	{
		JSONObject jsonObj = getJsonObjFromRequest();
		sysUserinfo.setUserid(jsonObj.getInt("userid"));
		sysUserinfo.setDeptid(jsonObj.getInt("deptid"));
		sysUserinfo.setUsername(jsonObj.getString("username"));
		sysUserinfo.setUsercode(jsonObj.getString("usercode"));
		sysUserinfo.setUserpwd(jsonObj.getString("userpwd"));
		sysUserinfo.setPhone(jsonObj.getString("phone"));
		sysUserinfo.setRemark(jsonObj.getString("remark"));
	   boolean ret =  sysUserInfoService.updateUserInfo(sysUserinfo);
		if(ret)
		{
			success = true;
			msg = "保存用户信息成功！";
		}
		else
		{
			success = false;
			msg = "保存用户信息失败！";						
		}	

		return SUCCESS;
	}
	
	/**
	 * 删除用户信息
	 */
	public String webeleteUserInfo() {
	   logger.error("webeleteUserInfo userid="+getParameterInteger("userid"));
	   logger.error("webeleteUserInfo usercode="+getParameterString("usercode"));
	   //sysUserinfo.setUserid(getParameterInteger("userid"));
	   sysUserinfo = sysUserInfoService.getUserInfoByUserCode(getParameterString("usercode"));
	   boolean ret =  sysUserInfoService.deleteUserInfo(sysUserinfo);
	   if (ret) 
	   {
			success = true;
			logger.info("删除用户信息成功!");
			
			statusCode="200";
			message="操作成功";
			navTabId="userinfo";
			rel="";
			callbackType="";
			forwardUrl="";
			confirmMsg="";
		}
	   else
	   {
		    success = true;
			logger.info("删除用户信息异常!");
			
			statusCode="200";
			message="操作失败";
			navTabId="userinfo";
			rel="";
			callbackType="";
			forwardUrl="";
			confirmMsg="";
			return SUCCESS;
	   }
		return SUCCESS;
	}
}
